package jiangyeheng;

public class Main {

    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle("矩形", 5.0, 3.0);
        rectangle.displayInfo();

        System.out.println();
        Circle circle = new Circle("圆形", 4.0);
        circle.displayInfo();

        System.out.println();

        Triangle triangle1 = new Triangle("三角形a", 3.0, 4.0, 5.0);
        triangle1.displayInfo();
        System.out.println("是否是等边三角形: " + triangle1.isRightTriangle());

        System.out.println();

        Triangle triangle2 = new Triangle("三角形b", 6.0, 6.0, 6.0);
        triangle2.displayInfo();
        System.out.println("是否是等边三角形: " + triangle2.isRightTriangle());

        System.out.println();

        Square square=new Square("正方形",4.0);
        square.displayInfo();
    }
}
class Shape{
    String name;
    public Shape() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Shape(String name) {
        this.name = name;
    }
    public double calculateArea(){
        return 0.00;
    }
    public double calculatePerimeter(){
        return 0.00;
    }
    public void displayInfo(){
        System.out.println("这个图形是"+name);
    }

}
class Rectangle extends Shape{
    double length;
    double width;

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public Rectangle() {
    }

    public Rectangle(String name, double length, double width) {
        super(name);
        this.length = length;
        this.width = width;
    }

    public double calculateArea(){
        return length*width;
    }
    public double calculatePerimeter(){
        return 2*(length+width);
    }

    public void displayInfo(){
        System.out.println("这个"+name+"的面积为:"+calculateArea()+"周长为"+calculatePerimeter());

    }
}
class Circle extends Shape{
    double radius;

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public Circle() {
    }

    public Circle(String name, double radius) {
        super(name);
        this.radius = radius;
    }


    public double calculatePerimeter(){
        return 2*Math.PI*radius;
    }

    public double calculateArea(){
        return Math.PI*radius*radius;
    }

    public void displayInfo(){
        System.out.println("这个圆形的面积为:"+calculateArea()+
                "周长为"+calculatePerimeter());
    }
}
class Triangle extends Shape{
    double side1;
    double side2;
    double side3;

    public Triangle(String name, double side1, double side2, double side3) {
        super(name);
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public double calculatePerimeter(){
        return side1+side2+side3;
    }

    public double calculateArea(){
        double s= calculatePerimeter()/2;
        return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
    }
    public void displayInfo(){
        System.out.println(name+"的周长为:"+calculatePerimeter()+"面积为:"+calculateArea());
    }
    public boolean isRightTriangle(){
        if(side1==side2&&side2==side3)
            return true;
        return false;
    }
}

class Square extends Shape{
    double length;

    public double calculateArea(){
        return length*length;
    }

    public double calculatePerimeter(){
        return length*4;
    }

    public void displayInfo(){
        System.out.println(name+"的面积是:"+calculateArea()+"周长是:"+calculatePerimeter());
    }
    public Square() {
    }

    public Square(String name, double length) {
        super(name);
        this.length = length;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }
}
